Skip to content

Fix PostgreSQL credential security and extract random string generation - #16

Merged
openshift-merge-bot[bot] merged 2 commits into
openstack-k8s-operators:mainfrom
lpiwowar:lpiwowar/postgresql-password
Jul 13, 2026
Merged

Fix PostgreSQL credential security and extract random string generation#16
openshift-merge-bot[bot] merged 2 commits into
openstack-k8s-operators:mainfrom
lpiwowar:lpiwowar/postgresql-password

Conversation

@lpiwowar

@lpiwowar lpiwowar commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

The previous PostgreSQL setup had several security and consistency problems:

Security issues:

  1. POSTGRESQL_ADMIN_PASSWORD was set, making the postgres superuser accessible remotely (not just locally via oc rsh + psql). [1]
  2. Both lightspeed-stack and llama-stack were connecting as the postgres superuser rather than a dedicated non-admin user.
  3. The postgres superuser username usage was hardcoded and credential paths into the app and db pods were inconsistent.

Naming/consistency issues:
4. lightspeed-stack used database "postgres" while llama-stack used "llamastack", with no explicit database name in llama-stack's config.
5. POSTGRES_USER/POSTGRES_PASSWORD env var names did not follow the POSTGRESQL_* convention of the PostgreSQL container image and also the usage of these env vars was insonsistent across the operator code.
6. Bootstrap SQL was embedded in postgres_bootstrap.sh, making it hard to read and maintain.

Fixes:

  • Remove POSTGRESQL_ADMIN_PASSWORD. The postgres superuser is now only accessible locally via oc rsh + psql (no password required).
  • Introduce a dedicated non-admin user "lightspeed-app-user", stored in lightspeed-postgres-secret alongside the password. Both apps now connect as this user via POSTGRESQL_USER and POSTGRESQL_PASSWORD.
  • Rename the lightspeed-stack database from postgres to lightspeed-stack and make llama-stack's llamastack database selection explicit in its config.
  • Rename POSTGRES_USER/POSTGRES_PASSWORD -> POSTGRESQL_USER/POSTGRESQL_PASSWORD throughout to match the container image's naming convention.
  • Extract bootstrap SQL into postgres_bootstrap.sql to enable syntax highlighting and improve maintainability.

[1] https://github.com/sclorg/postgresql-container/blob/master/src/root/usr/share/container-scripts/postgresql/README.md#postgresql-admin-account

@openshift-ci

openshift-ci Bot commented Jul 10, 2026

Copy link
Copy Markdown

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@lpiwowar
lpiwowar force-pushed the lpiwowar/postgresql-password branch 3 times, most recently from cf56b81 to be4035f Compare July 10, 2026 16:15

@umago umago left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Lukas! I know this is draft still but it looks good.

Only thing I would say is that a 16 character password seems a bit too weak. I would do at least 32 to be on the safe-side here.

Comment thread internal/controller/postgres_reconciler.go Outdated
Comment thread internal/controller/lcore_deployment.go Outdated
@lpiwowar
lpiwowar force-pushed the lpiwowar/postgresql-password branch from be4035f to 5097f7f Compare July 13, 2026 10:16
@lpiwowar lpiwowar changed the title Drop usage of postgres user Fix PostgreSQL credential security and extract random string generation Jul 13, 2026
@lpiwowar
lpiwowar marked this pull request as ready for review July 13, 2026 10:24
@openshift-ci
openshift-ci Bot requested review from Akrog and umago July 13, 2026 10:24
umago
umago previously approved these changes Jul 13, 2026

@umago umago left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Tests are still running but the code looks good to me!

Comment thread internal/controller/assets/postgres_bootstrap.sh
lpiwowar added 2 commits July 13, 2026 07:57
The previous PostgreSQL setup had several security and consistency
problems:

Security issues:
1. POSTGRESQL_ADMIN_PASSWORD was set, making the postgres superuser
   accessible remotely (not just locally via `oc rsh` + `psql`). [1]
2. Both lightspeed-stack and llama-stack were connecting as the postgres
   superuser rather than a dedicated non-admin user.
3. The postgres superuser username usage was hardcoded and credential
   paths into the app and db pods were inconsistent.

Naming/consistency issues:
4. lightspeed-stack used database "postgres" while llama-stack used
   "llamastack", with no explicit database name in llama-stack's config.
5. POSTGRES_USER/POSTGRES_PASSWORD env var names did not follow the
   POSTGRESQL_* convention of the PostgreSQL container image and also
   the usage of these env vars was insonsistent across the operator
code.
6. Bootstrap SQL was embedded in postgres_bootstrap.sh, making it hard
   to read and maintain.

Fixes:
- Remove POSTGRESQL_ADMIN_PASSWORD. The postgres superuser is now only
  accessible locally via `oc rsh` + `psql` (no password required).
- Introduce a dedicated non-admin user "lightspeed-app-user", stored in
  lightspeed-postgres-secret alongside the password. Both apps now
  connect as this user via POSTGRESQL_USER and POSTGRESQL_PASSWORD.
- Rename the lightspeed-stack database from "postgres" to
  "lightspeed-stack" and make llama-stack's "llamastack" database
  selection explicit in its config.
- Rename POSTGRES_USER/POSTGRES_PASSWORD ->
  POSTGRESQL_USER/POSTGRESQL_PASSWORD throughout to match the container
  image's naming convention.
- Extract bootstrap SQL into postgres_bootstrap.sql to enable syntax
  highlighting and improve maintainability.

[1]
https://github.com/sclorg/postgresql-container/blob/master/src/root/usr/share/container-scripts/postgresql/README.md#postgresql-admin-account
Move generateRandomString from postgres_reconciler.go to common.go so
the helper is available across the package. Add tests covering output
length, hex character validity, and uniqueness.

Also, make the generated password longer and thus more secure
(16 -> 32).
@lpiwowar
lpiwowar force-pushed the lpiwowar/postgresql-password branch from 5097f7f to 505896b Compare July 13, 2026 12:02
@openshift-ci

openshift-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lpiwowar, umago

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@umago

umago commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Waiting tests before final approval

@umago

umago commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label Jul 13, 2026
@openshift-merge-bot
openshift-merge-bot Bot merged commit 6161942 into openstack-k8s-operators:main Jul 13, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants